<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>我的信息</title>
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<script src="js/mui.min.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<style>
			html,
			body {
				height: 100%;
			}

			#name {
				color: #ffffff;
				font-size: 2em;
			}

			.des {
				color: #ffffff;
				font-size: 1em;
			}

			#description {
				color: #ffffff;
				font-size: 2em;
			}
		</style>
	</head>
	<body>
		<div class="mui-content" style="height:100%">
			<div style="background: #2196f3;height:40%">
				<div style="padding-left: 10%; padding-top: 5%;">
					<p id="name">我的信息</p>
					<p><span class="des" id="sign">用户很懒，什么也没有写</span><span id="description" class="mui-icon mui-icon-compose"></span></p>
				</div>
			</div>

			<div class="mui-card" style="background: #ffffff;" onclick="mui.openWindow({url:'group3/edit_myinfo.html'})">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						编辑资料
					</div>
				</div>
			</div>

			<div class="mui-card" style="background: #ffffff;" onclick="mui.openWindow({url:'group3/edit_pwd.html'})">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						修改密码
					</div>
				</div>
			</div>

			<div class="mui-card" style="background: #ffffff;" onclick="mui.openWindow({url:'group3/my_fabu.html'})">
				<div class="mui-card-content">
					<div class="mui-card-content-inner">
						我的发布
					</div>
				</div>
			</div>
		</div>

		<ul class="mui-table-view" style="position: absolute;bottom: 0;width: 100%;">
			<li class="mui-table-view-cell" style="text-align: center;color: #ff0000;">
				<a id='exit'>退出</a>
			</li>
		</ul>

	</body>
	<script>
		var user_id, sign;
		mui.plusReady(function() {
			user_id = plus.storage.getItem('uID');
			init();
		});

		//退出
		document.getElementById("exit").addEventListener('tap', function(e) {
			var btnArray = ['否', '是'];
			mui.confirm('您确定要退出？', '提示', btnArray, function(e) {
				if (e.index == 1) {
					plus.storage.setItem('uID', '');
					plus.runtime.quit();
				}
			})
		});

		function init() {
			mui.ajax({
				url: 'http://120.27.247.180:8080/School/users/showMessage',
				type: "post",
				async: false,
				data: {
					"uID": user_id
				},
				dataType: "json",
				contentType: "application/x-www-form-urlencoded; charset=utf-8",
				jsonp: "jsoncallback",
				success: function(data) {
					// console.log(data);
					jQuery("#name").text(data.users.userName);
					if (data.users["signature"].length === 0) {
						jQuery("#sign").text('用户很懒，什么也没有写');
					} else{
						jQuery("#sign").text(data.users["signature"]);
					}
				},
				error: function() {
					mui.toast("网络异常");
				}
			})
		}

		document.getElementById("description").addEventListener('tap', function(e) {
			var btnArray = ['否', '是'];
			mui.prompt('修改个性签名：', '', '提示', btnArray, function(e) {
				if (e.index == 1) {
					mui.ajax({
						url: 'http://120.27.247.180:8080/School/users/updateMessage',
						type: "post",
						async: false,
						data: {
							"uID": user_id,
							"signature": e.value
						},
						dataType: "jsonp",
						contentType: "application/x-www-form-urlencoded; charset=utf-8",
						jsonp: "jsoncallback",
						success: function(data) {
							data = JSON.parse(data);
							if (data.suc) {
								mui.toast("修改成功");
								setTimeout(function() {
									init();
								}, 1000);

							} else
								mui.toast("修改失败");
						},
						error: function() {
							mui.toast("网络异常");
						}
					});
				}
			});
		});
	</script>
</html>
